	package com.finiac.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.finiac.model.StockAlertSettings;

public class StockAlertSettingsDAOImpl implements StockAlertSettingsDAO {

	private HibernateTemplate hibernateTemplate;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	@SuppressWarnings("unchecked")
	@Override
	public StockAlertSettings getSettings() {
		List<StockAlertSettings> settingsList=hibernateTemplate.find("from StockAlertSettings where variable='min_qty'");
		StockAlertSettings stockAlertSettings = new StockAlertSettings();
		for(int i=0;i<settingsList.size();i++)
		{
			stockAlertSettings = settingsList.get(i);
		}
		return stockAlertSettings;
	}

	@Override
	public void updateSettings(StockAlertSettings settings) {
		hibernateTemplate.update(settings);
		
	}

	@Override
	public void initStockAlert(StockAlertSettings settings) {
		hibernateTemplate.save(settings);
		
	}
	
}
